<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/5/14
 * Time: 上午9:55
 */

namespace Home\Model;
use Think\Model\BaseModel;

class PracticeModel extends BaseModel{
    protected  $_link = array(
        'Exercise'=>array(
            'mapping_type' => self::BELONGS_TO,
//              'class_name' => 'Course',
            'foreign_key' => 'exe_id',

            'mapping_fields' => array('exe_type','exe_difficulty','exe_title','tea_id','poi_id','exe_valid'),
            'as_fields' => 'exe_type,exe_difficulty,exe_title,tea_id,poi_id,exe_valid'
        ),
        'Teacher' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Teacher',
            'foreign_key' => 'tea_id',
            'mapping_fields' => 'tea_name',
            'as_fields' => 'tea_name'
        ),
        'Point'=>array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Point',
            'foreign_key' => 'poi_id',
            'mapping_fields' => 'poi_content',
            'as_fields' => 'knowledge_content'
        )
    );
    public function getPracticeInfoListWithCourseName($section_id){
        if ($section_id == 0){
            $section_id = array('like','%%');
        }
        $result = $this-> where(array('sec_id'=>$section_id)) -> relation(true) -> select();
        if($result){

            foreach($result as $key => $value){
                if ($value['exe_valid'] == '1'){
                    $result[$key]['exe_valid'] = '有效';
                }else{
                    $result[$key]['exe_valid'] = '无效';
                }
            }
            return $result;
        }else{
            return array();
        }
    }

}